package cn.richard.demo.easyrules.tax;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.math.BigDecimal;

import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rule;
import org.jeasy.rules.api.Rules;
import org.jeasy.rules.api.RulesEngine;
import org.jeasy.rules.core.DefaultRulesEngine;
import org.jeasy.rules.mvel.MVELRuleFactory;
import org.jeasy.rules.support.reader.YamlRuleDefinitionReader;

import cn.richard.demo.easyrules.launcher.MvelAndFileLauncher;

public class Launcher {
	public static void main(String[] args) throws FileNotFoundException, Exception {
		TaxDto tax = new TaxDto(BigDecimal.valueOf(8000L));
		System.err.println(tax);
		Facts facts = new Facts();
        facts.put("tax", tax);
        
        Rule taxRule = new MVELRuleFactory(new YamlRuleDefinitionReader()).createRule(new FileReader(MvelAndFileLauncher.class.getClassLoader().getResource("tax-rule.yml").getFile()));
        Rules rules = new Rules();
        rules.register(taxRule);
        
        RulesEngine rulesEngine = new DefaultRulesEngine();
        rulesEngine.fire(rules, facts);
        
        tax.paidResult();
        System.err.println(tax);
	}
}
